// 获取元素，绑定事件
const cover = document.querySelector('.cover')
const removes = document.querySelector('.remove')
const num = document.querySelector('.number')
//绑定鼠标按下时事件：
removes.onmousedown = function (event) {
  let events = event || window.event
  let q = event.clientX - removes.offsetLeft
  //console.log(q);
  document.onmousemove = function (event) {
    let events = event || window.event
    let x = event.clientX - q
    console.log(x)
    if (x <= 0) {
      x = 0
    }
    if (x >= removes.parentNode.offsetWidth - removes.offsetWidth) {
      x = removes.parentNode.offsetWidth - removes.offsetWidth
    }
    removes.style.left = x + 'px'
    cover.style.width = x + 'px'
    //计算百分比：
    num.innerHTML = '分数：' + parseInt((x / (removes.parentNode.offsetWidth - removes.offsetWidth)) * 100)
  }
  document.onmouseup = function () {
    document.onmousemove = ''
    document.onmouseup = ''
  }

  return false
}
